package com.bjsxt.controller.statistics;

import cn.hutool.core.date.DateUtil;
import com.bjsxt.controller.BaseController;
import com.bjsxt.domain.Check;
import com.bjsxt.domain.CheckStat;
import com.bjsxt.dto.CheckQueryDto;
import com.bjsxt.service.CheckService;
import com.bjsxt.vo.AjaxResult;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("statistics/check")
public class CheckStatController extends BaseController {

    @Reference
    private CheckService checkService;

    /**
     * 查询检查项目列表
     *
     * @param checkQueryDto
     * @return
     */
    @GetMapping("queryCheck")
    @HystrixCommand
    public AjaxResult queryCheck(CheckQueryDto checkQueryDto) {
        if (checkQueryDto.getBeginTime() != null) {
            checkQueryDto.setQueryDate(DateUtil.format(DateUtil.date(), "yyyy-MM-dd"));
        }
        List<Check> checks = this.checkService.queryCheck(checkQueryDto);
        return AjaxResult.success(checks);
    }


    /**
     * 查询检查项目统计列表
     *
     * @param checkQueryDto
     * @return
     */
    @GetMapping("queryCheckStat")
    @HystrixCommand
    public AjaxResult queryCheckStat(CheckQueryDto checkQueryDto) {
        if (checkQueryDto.getBeginTime() == null) {
            checkQueryDto.setQueryDate(DateUtil.format(DateUtil.date(), "yyyy-MM-dd"));
        }
        List<CheckStat> checkStats = this.checkService.queryCheckStat(checkQueryDto);
        return AjaxResult.success(checkStats);
    }

}